package com.action.boot.mongo.mongo_template.service;

import com.action.boot.mongo.mongo_template.dao.BathUpdateDao;
import com.action.boot.mongo.mongo_template.entity.BulkInfo;
import com.action.boot.mongo.mongo_template.entity.BulkList;
import com.action.boot.mongo.mongo_template.entity.TestBath;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Wuxiang on 2017/11/3.
 */
@Service
public class BathUpdateService {
    @Autowired
    BathUpdateDao bathUpdateDao;

    public int bathAdd() {
        List<TestBath> testBaths = new ArrayList<>();
        testBaths.add(new TestBath("a","b","c","d"));
        testBaths.add(new TestBath("1","2","3","4"));
        testBaths.add(new TestBath("q","w","e","r"));
        return bathUpdateDao.bathAdd(testBaths);
    }

    public int bathUpdate() {
        List<TestBath> testBaths = new ArrayList<>();
        testBaths.add(new TestBath("a", "bbb", "ccc", "ddd"));
        testBaths.add(new TestBath("1", "222", "333", "444"));
        testBaths.add(new TestBath("q", "www", "eee", "rrr"));
        return bathUpdateDao.bathUpdate(testBaths);
    }

    public int bulkAdd() {

        List<BulkList> bulkLists = new ArrayList<>();
        bulkLists.add(new BulkList("1号街", "111"));
        bulkLists.add(new BulkList("2号街", "222"));
        List<BulkList> bulkLists2 = new ArrayList<>();
        bulkLists2.add(new BulkList("3号街", "333"));
        bulkLists2.add(new BulkList("4号街", "444"));

        List<BulkInfo> bulkInfos = new ArrayList<>();
        bulkInfos.add(new BulkInfo("1", "aaa", bulkLists));
        bulkInfos.add(new BulkInfo("2", "bbb", bulkLists));
        bulkInfos.add(new BulkInfo("3", "ccc", bulkLists2));

        return bathUpdateDao.bulkAdd(bulkInfos);
    }

    public int bulkUpdate() {
        List<BulkList> bulkLists = new ArrayList<>();
        bulkLists.add(new BulkList("11号街", "111111"));
        bulkLists.add(new BulkList("2号街", "2223333"));
        List<BulkList> bulkLists2 = new ArrayList<>();
        bulkLists2.add(new BulkList("33号街", "3334444"));
        bulkLists2.add(new BulkList("4号街", "444555"));

        List<BulkInfo> bulkInfos = new ArrayList<>();
        bulkInfos.add(new BulkInfo("1", "wxxx", bulkLists2));
        bulkInfos.add(new BulkInfo("2", "addd", bulkLists));
        bulkInfos.add(new BulkInfo("3", "fhhh", bulkLists2));

        return bathUpdateDao.bulkUpdate(bulkInfos);
    }
}
